package cn.stylefeng.guns.sys.modular.system.controller;

import cn.stylefeng.guns.base.pojo.page.LayuiPageInfo;
import cn.stylefeng.guns.sys.core.util.JsonResult;
import cn.stylefeng.guns.sys.modular.system.entity.BtyElmsxf;
import cn.stylefeng.guns.sys.modular.system.model.params.BtyElmsxfParam;
import cn.stylefeng.guns.sys.modular.system.service.BtyElmsxfService;
import cn.stylefeng.roses.core.base.controller.BaseController;
import cn.stylefeng.roses.core.reqres.response.ResponseData;
import cn.stylefeng.roses.core.util.ToolUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.multipart.MultipartFile;


/**
 * 控制器
 *
 * @author liuy
 * @Date 2021-10-12 14:46:50
 */
@Controller
@RequestMapping("/btyElmsxf")
public class BtyElmsxfController extends BaseController {

    private String PREFIX = "/modular/system/btyElmsxf";

    @Autowired
    private BtyElmsxfService btyElmsxfService;

    /**
     * 跳转到主页面
     *
     * @author liuy
     * @Date 2021-10-12
     */
    @RequestMapping("")
    public String index() {
        return PREFIX + "/btyElmsxf.html";
    }

    /**
     * 新增页面
     *
     * @author liuy
     * @Date 2021-10-12
     */
    @RequestMapping("/add")
    public String add() {
        return PREFIX + "/btyElmsxf_add.html";
    }

    /**
     * 编辑页面
     *
     * @author liuy
     * @Date 2021-10-12
     */
    @RequestMapping("/edit")
    public String edit() {
        return PREFIX + "/btyElmsxf_edit.html";
    }

    /**
     * 新增接口
     *
     * @author liuy
     * @Date 2021-10-12
     */
    @RequestMapping("/addItem")
    @ResponseBody
    public ResponseData addItem(BtyElmsxfParam btyElmsxfParam) {
        this.btyElmsxfService.add(btyElmsxfParam);
        return ResponseData.success();
    }

    /**
     * 编辑接口
     *
     * @author liuy
     * @Date 2021-10-12
     */
    @RequestMapping("/editItem")
    @ResponseBody
    public ResponseData editItem(BtyElmsxfParam btyElmsxfParam) {
        this.btyElmsxfService.update(btyElmsxfParam);
        return ResponseData.success();
    }

    /**
     * 删除接口
     *
     * @author liuy
     * @Date 2021-10-12
     */
    @RequestMapping("/delete")
    @ResponseBody
    public ResponseData delete(BtyElmsxfParam btyElmsxfParam) {
        this.btyElmsxfService.delete(btyElmsxfParam);
        return ResponseData.success();
    }

    /**
     * 查看详情接口
     *
     * @author liuy
     * @Date 2021-10-12
     */
    @RequestMapping("/detail")
    @ResponseBody
    public ResponseData detail(BtyElmsxfParam btyElmsxfParam) {
        BtyElmsxf detail = this.btyElmsxfService.getById(btyElmsxfParam.getId());
        return ResponseData.success(detail);
    }

    /**
     * 查询列表
     *
     * @author liuy
     * @Date 2021-10-12
     */
    @ResponseBody
    @RequestMapping("/list")
    public LayuiPageInfo list(BtyElmsxfParam btyElmsxfParam) {
        return this.btyElmsxfService.findPageBySpec(btyElmsxfParam);
    }

    /**
     * 导入excel
     */
    @RequestMapping("/import")
    @ResponseBody
    public Object addUser(@RequestParam("file") MultipartFile file,BtyElmsxfParam btyElmsxfParam) {
        String fileName = file.getOriginalFilename();
        Boolean flag;
        JsonResult jsonResult = new JsonResult();
        if(ToolUtil.isEmpty(btyElmsxfParam.getZdrq())){
            jsonResult.setState(0);
            jsonResult.setErrmsg("请先选择制单日期！");
            return jsonResult;
        }
        try {
            flag = btyElmsxfService.batchImport(fileName, file,btyElmsxfParam);
        } catch (Exception e) {
            e.printStackTrace();
            jsonResult.setState(0);
            jsonResult.setErrmsg(e.getMessage());
            return jsonResult;
        }
        return flag;
    }

}


